const pool = require('../../mysql/Dao/sql')
const NewsService={
    AddNews:async (data)=>{
          try{
                let sql = 'insert into news(title,content,category,isPublish,cover,editTime) value(?,?,?,?,?,?)'
                return pool(sql,data)
          }
          catch(err){
            return {err:err,code:0}
          }
    },
    GetAllNews:async()=>{
        try{        
                    let params=[]
                    let sql ='select * from news'
                  return pool(sql,params)
        }
        catch(err){
            return {err:err,code:0}
        }
    },
    isPublish:async(data)=>{
        try{
            let params=data
            let sql = 'update news set isPublish=? where id=?'
            return pool(sql,params)
        }
        catch(err){
            return {err:err,code:0}
        }
    },
    Newdelete:async(data)=>{
        try{
                let params=data
                let sql='delete from news where id=?'
                return pool(sql,params)
        }
        catch(err){
            return{
                err:err,
                code:0
            }
        }
    },
    NewEdit:async(sql,params)=>{
        try{
                return pool(sql,params)
        }
        catch(err){
            return{err:err,code:0}
        }
    }
}

module.exports = NewsService